﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 故障级别
    /// </summary>
    public enum FaultLevel
    {
        /// <summary>
        /// 等级低
        /// 一般警示类，不影响生产过程
        /// 或有替代方案，不需要马上解决的警示
        /// </summary>
        Warning = 0,
        /// <summary>
        /// 等级中
        /// 设备故障类，影响当前工位生产
        /// 常见于同工序双工位以上设备，单工位故障不影响其它工位正常生产
        /// 当前工序所有工位出现故障，应该将等级设置为高
        /// </summary>
        Fault = 1,
        /// <summary>
        /// 等级高
        /// 生产单元级以上的故障，直接影响整线生产
        /// 或影响安全生产的故障
        /// 需要马上解决的故意
        /// </summary>
        Deadly = 2
    }

    /// <summary>
    /// 故障类型
    /// </summary>
    public partial class FaultType : BusEntity
    {
        /// <summary>
        /// 故障类型编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 故障类型名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 故障级别
        /// </summary>
        public FaultLevel Level { set; get; }
        /// <summary>
        /// 故障描述
        /// </summary>
        public string Desc { set; get; }
        /// <summary>
        /// 排查解决办法
        /// </summary>
        public string Solution { set; get; }
    }

    public partial class FaultType : BusEntity
    {
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class FaultTypeTypeConfig : BusEntityTypeConfig<FaultType>, IEntityTypeConfiguration<FaultType>
    {
        public override void Configure(EntityTypeBuilder<FaultType> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Level).IsRequired();
            builder.Property(p => p.Desc).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.Solution).HasMaxLength(EntityDefinition.DefLargeColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("故障类型");
            builder.Property(p => p.Code).HasComment("故障类型编码");
            builder.Property(p => p.Name).HasComment("故障类型名称");
            builder.Property(p => p.Level).HasComment("故障级别");
            builder.Property(p => p.Desc).HasComment("故障描述");
            builder.Property(p => p.Solution).HasComment("排查解决办法");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
